/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.ManageClassEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class ManageClassMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.selectAll
    
    public List<ManageClassEntity> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_ManageClass where `stopstatus`= 0 and `ytenant_id`=?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new ManageClassEntity());
        return (List<ManageClassEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(ManageClassEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_ManageClass set `parent` = ?, `code` = ?, `level` = ?, `isEnd` = ?, `path` = ?, `order` = ?, `classname` = ?, `ytenant_id` = ?, `stopstatus` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getParent(), Types.BIGINT);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getLevel(), Types.INTEGER);
		parameter.addParamWithType(record.getIsEnd(), Types.BIT);
		parameter.addParamWithType(record.getPath(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrder(), Types.INTEGER);
		parameter.addParamWithType(record.getClassname(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);
		parameter.addParamWithType(record.getStopstatus(), Types.INTEGER);
		parameter.addParamWithType(record.getId(), Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.insertBatch
    
    public int insertBatch(List<ManageClassEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_ManageClass (`id`, `parent`, `code`, `level`, `isEnd`, `path`, `order`, `stopstatus`, `classname`, `ytenant_id`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				ManageClassEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getParent(), Types.BIGINT);
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getLevel(), Types.INTEGER);
				parameter.addParamWithType(item.getIsEnd(), Types.BIT);
				parameter.addParamWithType(item.getPath(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrder(), Types.INTEGER);
				parameter.addParamWithType(item.getStopstatus(), Types.INTEGER);
				parameter.addParamWithType(item.getClassname(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenant_id(), Types.VARCHAR);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE `parent`=VALUES(parent), `code`=VALUES(code), `level`=VALUES(level), `isEnd`=VALUES(isEnd), `path`=VALUES(`path`), `order`=VALUES(`order`), `stopstatus`=VALUES(`stopstatus`), classname=VALUES(classname), `tenant_id`=VALUES(tenant_id) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_ManageClass where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.insert
    
    public int insert(ManageClassEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_ManageClass (`id`, `parent`,  `code`, `level`, `isEnd`,  `path`, `order`,  `stopstatus`, `classname`, `ytenant_id`) values (?, ?,  ?, ?, ?,  ?, ?,  ?, ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getParent(), Types.BIGINT);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getLevel(), Types.INTEGER);
		parameter.addParamWithType(record.getIsEnd(), Types.BIT);
		parameter.addParamWithType(record.getPath(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrder(), Types.INTEGER);
		parameter.addParamWithType(record.getStopstatus(), Types.INTEGER);
		parameter.addParamWithType(record.getClassname(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenant_id(), Types.VARCHAR);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_ManageClass where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ManageClassMapper.selectById
    
    public ManageClassEntity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_ManageClass where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new ManageClassEntity());
        return (ManageClassEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

}
